package com.szxy.service.impl;

import com.szxy.service.BusinessService;
import com.szxy.service.feign.StorageServiceFeign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Author: zwz
 * @Date:2020/7/15 22:41
 * @Description:com.szxy.service.impl
 * @Version:1.0
 **/
@Service
public class StorageServiceApi {

//    @Autowired
//    private RestTemplate restTemplate;

    @Autowired
    private StorageServiceFeign storageServiceFeign;

    /**
     * 记录日志
     */
    private static final Logger logger = LoggerFactory.getLogger(StorageServiceApi.class);

    /**
     * 扣库存
     * @param productId
     * @param count
     */
    public void dePuct(String productId, int count) {
//        ResponseEntity<Void> restTemplateForEntity = this.restTemplate.getForEntity(
//                "http://storage-service/dePuct/{productName}/{count}",
//                Void.class,
//                productId,
//                count);
        ResponseEntity<Void> restTemplateForEntity = this.storageServiceFeign.dePuct(productId, count);
        if (restTemplateForEntity.getStatusCode() == HttpStatus.OK) {
            logger.info("远程调用 Storage 服务成功！");
            return;
        }
        throw new RuntimeException("远程调用 Storage 服务失败 ...");
    }
}
